package com.example.springcloudusageserver.controller;

import com.example.springcloudusageserver.response.JsonResult;
import com.example.springcloudusageserver.response.SelectResult;
import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.example.springcloudusageserver.service.BlockchainService;
import com.example.springcloudusageserver.service.ExampleService;

import java.math.BigInteger;


@Slf4j
@RestController
@RequestMapping("/usage")
public class UsageController {

    @Autowired
    private BlockchainService blockchainService;

    @Autowired
    private ExampleService exampleService;

    @GetMapping("/testBlockchain")
    public String testBlockchain(){
        return blockchainService.hello();
    }

    @GetMapping("/testInsert")
    public JsonResult testInsert(){
        return blockchainService.CRUDInsert("modelA","modelsku123",String.valueOf(blockchainService.CRUDSelect("modelA").getCount().add(BigInteger.ONE)));
    }

    @GetMapping("/testSelect")
    public SelectResult testSelect(){return blockchainService.CRUDSelect("modelA"); }

    @GetMapping("/testUsage")
    public String testModel(){
        return "Test Usage Server";
    }

    @GetMapping("/testExampleService")
    public String testExampleService(){
        return exampleService.testExample();
    }

    @PostMapping("/calculate")
    public int localCalculate(@RequestParam("input1") int input1, @RequestParam("input2") int input2){
        return exampleService.calculate(input1,input2);
    }
}
